package com.jueming.miser.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.jueming.miser.order.to.MiserOrderTo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jueming.miser.order.entity.MiserOrderEntity;
import com.jueming.miser.order.service.MiserOrderService;
import com.jueming.miser.common.utils.PageUtils;
import com.jueming.miser.common.utils.R;


/**
 * 
 *
 * @author jueming
 * @email jueming@qq.com
 * @date 2022-10-04 11:06:57
 */
@RestController
@RequestMapping("order/miserorder")
public class MiserOrderController {
    @Autowired
    private MiserOrderService miserOrderService;


    @RequestMapping("/saveto")
    public R saveto(@RequestBody MiserOrderTo to){
        MiserOrderEntity entity = new MiserOrderEntity();
        BeanUtils.copyProperties(to, entity);

        return save(entity);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = miserOrderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{orderId}")
    public R info(@PathVariable("orderId") Integer orderId){
		MiserOrderEntity miserOrder = miserOrderService.getById(orderId);

        return R.ok().put("miserOrder", miserOrder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MiserOrderEntity miserOrder){
		miserOrderService.save(miserOrder);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MiserOrderEntity miserOrder){
		miserOrderService.updateById(miserOrder);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] orderIds){
		miserOrderService.removeByIds(Arrays.asList(orderIds));

        return R.ok();
    }

}
